<?php namespace Admin\Controller;

//默认控制器
class IndexController extends CommonController{

    //后台首页
    public function index(){
        // p($_SESSION);
        // p(Rbac::isSuperUser());die;
       View::make();
    }

    //欢迎页面
    public function welcome(){
    	View::make();
    }

    //修改密码
    public function changePassword(){
    	if (IS_POST) {
    		//判断密码是否少于6位
            $newPassword=Q('post.newPassword');
            if (strlen($newPassword)<6) View::error('密码格式不正确');
            //判断两个新密码是否一致
            $confirmPassword=Q('post.confirmPassword');
            if ($newPassword != $confirmPassword) View::error('两个密码不一致');
            //原密码是否正确
            $aid=$_SESSION['aid'];
            $data=Db::table('admin')->where("aid={$aid}")->get();
            $oldPassword=Q('post.oldPassword','','md5');
            if ($oldPassword != $data[0]['adminpwd']) View::error('原密码错误');
            //修改密码
            Db::table('admin')->where("aid={$aid}")->update(['adminpwd'=>md5($newPassword)]);
            //清除session
            session_unset($_SESSION['aid']);
            session_destroy();
            echo "<script type='text/javascript'>window.parent.location.reload();</script>";
            View::success('修改成功');
    	}
    	View::make();
    }
}
